package game.classes.particles.displays
{
	import engine.utils.MathUtils;
	
	import flash.display.Shape;
	
	public class Polygon extends Shape
	{
		private var _color:uint;
		private var _radius:Number;
		private var _numPoints:int;
		
		public function Polygon(color:uint, radius:Number, numPoints:Number)
		{
			this._color = color;
			this._radius = radius;
			this._numPoints = numPoints;
			
			this.draw();
		}
		
		private function draw():void
		{
			var radians:Number = 0;
			var offset:Number = MathUtils.PI2 / this._numPoints;
			
			this.graphics.clear();
			this.graphics.beginFill(this._color);
			
			this.graphics.moveTo(Math.cos(radians) * this._radius, Math.sin(radians) * this._radius);
			radians += offset;
			
			while(radians < MathUtils.PI2)
			{
				this.graphics.lineTo(Math.cos(radians) * this._radius, Math.sin(radians) * this._radius);
				radians += offset;
			}
			
			this.graphics.endFill();
		}
		
		public function get color():uint { return this._color; }
		public function set color(color:uint):void
		{
			this._color = color;
			this.draw();
		}
		
		public function get radius():Number { return this._radius; }
		public function set radius(radius:Number):void
		{
			this._radius = radius;
			this.draw();
		}
		
		public function get numPoints():int { return this._numPoints; }
		public function set numPoints(numPoints:int):void
		{
			this._numPoints = numPoints;
			this.draw();
		}
	}
}